package com.yc.system.security.core.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.system.entity.Role;
import com.yc.system.entity.User;
import com.yc.system.security.core.entity.SysMenuEntity;
import com.yc.system.security.core.entity.SysRoleEntity;
import com.yc.system.security.core.entity.SysUserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description 系统用户DAO
 * @Author Sans
 * @CreateTime 2019/9/14 15:57
 */
@Mapper
public interface SysUserDao extends BaseMapper<User> {

    /**
     * 通过用户ID查询角色集合
     * @Author Sans
     * @CreateTime 2019/9/18 18:01
     * @Param  userId 用户ID
     * @Return List<SysRoleEntity> 角色名集合
     */
    @Select("SELECT sr.* FROM t_role sr\n" +
            "LEFT JOIN t_user_role se ON se.role_id = sr.role_id\n" +
            "WHERE se.user_id = #{userId}")
    List<Role> selectSysRoleByUserId(Long userId);
    /**
     * 通过用户ID查询权限集合
     * @Author Sans
     * @CreateTime 2019/9/18 18:01
     * @Param  userId 用户ID
     * @Return List<SysMenuEntity> 权限名集合
     */
    @Select("SELECT DISTINCT m.* FROM t_user_role ur\n" +
            "LEFT JOIN sys_role_menu rm ON ur.role_id = rm.role_id\n" +
            "LEFT JOIN sys_menu m ON rm.menu_id = m.menu_id\n" +
            "WHERE ur.user_id = #{userId}")
    List<SysMenuEntity> selectSysMenuByUserId(Long userId);
	
}
